home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / make / icmake-6.000 / icmake-6 / icmake / exec / funfgets.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-02-08  |  1.3 KB  |  51 lines

  1. /*
  2. \funcref{fun\_fgets}{void fun\_fgets ()}
  3.     {}
  4.     {}
  5.     {}
  6.     {fun\_gets(), fun\_printf(), fun\_fprintf()}
  7.     {funfgets.c}
  8.     {
  9.  
  10.         This function reads in a string from a file and returns it in the {\em
  11.         reg} return register as an {\em e\_str} value. The arguments on the
  12.         stack are: the filename and an {\em int offset}, where the read
  13.         operation should start.
  14.  
  15.         The return value is a list, holding as the first list element the read
  16.         string and as the second element the offset where the reading operation
  17.         ended. The offset and the string are empty (offset 0, string "") when
  18.         the reading operation failed.
  19.  
  20.     }
  21. */
  22.  
  23. #include "icm-exec.h"
  24.  
  25. void fun_fgets ()
  26. {
  27.     char
  28.         buffer [255];
  29.     register char
  30.         *filename;
  31.     register int
  32.         offset;
  33.     register FILE
  34.         *inf;
  35.  
  36.     reg = newvar (e_list);
  37.     filename = stack [sp].vu.i->ls.str;
  38.     offset   = stack [sp - 1].vu.intval;
  39.  
  40.     if ( (inf = fopen (filename, "r"))          &&
  41.          ! fseek (inf, (long) offset, SEEK_SET) &&
  42.          fgets (buffer, 254, inf)
  43.        )
  44.     {
  45.         reg = addtolist (reg, buffer);
  46.         sprintf (buffer, "%d", (int) ftell (inf));
  47.         reg = addtolist (reg, buffer);
  48.         fclose (inf);
  49.     }
  50. }
  51.